package org.train.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.web.bind.annotation.*;
import org.train.entity.ReportPo;
import org.train.service.ReportService;
import org.train.util.R;
import org.train.util.RUtil;
import org.train.util.Renum;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/report")
public class ReportController{
    @Autowired
    private ReportService service;

    @PostMapping("/saveOrUpdateOne")
    public R saveOrUpdateOne(@RequestBody ReportPo po){
        if(po.getProjectId() == null
            || po.getReportName() == null
            || po.getWriter() == null){
            return RUtil.error(Renum.REQUIRED_FIELDS_MISSING);
        }
        service.saveOrUpdate(po);
        return RUtil.success();
    }

    @GetMapping("/queryAllInfos")
    public R queryAllInfos(Integer pageNum, Integer pageSize, String search){
        return service.queryAllInfos(pageNum, pageSize, search);
    }

    @GetMapping("/queryDetail")
    public R queryDetail(@RequestParam Integer id){
        return service.queryDetail(id);
    }

    @PostMapping("/removeBatch")
    public R removeBatch(@RequestBody List<Integer> ids){
        service.update(new UpdateWrapper<ReportPo>()
                .in("id", ids)
                .set("deleted", 1));
        return RUtil.success();
    }
}
